package com.xhs.controller;

import com.xhs.design.factory.TemplateFactory;
import com.xhs.dto.request.LoginTemplateRequest;
import com.xhs.message.ReturnResult;
import com.xhs.service.AbstractLoginTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @desc: 模板方法
 * @projectName: tools-parent
 * @author: xhs
 * @date: 2022/12/4 23:09
 * @version: JDK 1.8
 */
@RestController
@RequestMapping("/template")
public class TemplateController {

    /**
     * 登录接口
     *
     * @param loginTemplateRequest
     * @return
     */
    @PostMapping("/login")
    public ReturnResult<String> login(@RequestBody LoginTemplateRequest loginTemplateRequest) {
        // 也可以使用策略模式获取对应的模板
        AbstractLoginTemplate loginTemplate = TemplateFactory.getLoginTemplate(loginTemplateRequest.getTemplateId());
        String login = loginTemplate.login();
        return ReturnResult.success(login);
    }

}
